package site.xuxingcan;

import io.netty.channel.ChannelHandlerContext;

import java.util.HashMap;

public class HttpServerHandlerImp extends HttpServerHandlerInterface {
    @Override
    public void onGetRequest(ChannelHandlerContext ctx, HashMap<String, String> parHashMap) throws Exception {
        writeAndFlushResponse(ctx, 1, "use post please!!!");
    }

    @Override
    public void onPostRequest(ChannelHandlerContext ctx, HashMap<String, String> parHashMap) throws Exception {
        String action = parHashMap.get("action");
        if (action == null) {
            action = "";
        }
        switch (action) {
            case "normal": {
                String key = parHashMap.get("key");
                if (MysqlUtil.getInstance().isKeyRight(key)) {
                    writeAndFlushResponse(ctx, 1, gson.toJson(MysqlUtil.getInstance().getNormalUrlList()));
                } else {
                    writeAndFlushResponse(ctx, 2, "key is not right");
                }
            }
            break;
            case "key": {
                String key = parHashMap.get("key");
                if (MysqlUtil.getInstance().isKeyRight(key)) {
                    writeAndFlushResponse(ctx, 1, gson.toJson(MysqlUtil.getInstance().getAuthUrlList()));
                } else {
                    writeAndFlushResponse(ctx, 2, "key is not right");
                }
            }
            break;
            case "IMEI_DIANXIN": {
                String key = parHashMap.get("key");
                if (MysqlUtil.getInstance().isIMEIKeyRight(key)) {
                    writeAndFlushResponse(ctx, 1, MysqlUtil.getInstance().getDianxinContent());
                } else {
                    writeAndFlushResponse(ctx, 2, "key is not right");
                }
            }
            break;
            case "IMEI_LIANTONG": {
                String key = parHashMap.get("key");
                if (MysqlUtil.getInstance().isIMEIKeyRight(key)) {
                    writeAndFlushResponse(ctx, 1, MysqlUtil.getInstance().getLiantongContent());
                } else {
                    writeAndFlushResponse(ctx, 2, "key is not right");
                }
            }
            break;
            default: {
                writeAndFlushResponse(ctx, 3, "no action!!!");
            }
            break;
        }
    }
}